package com.common.allCommon;

import java.util.regex.Pattern;

import android.util.Patterns;

public class RegexUtils {

	/**
	 * 用正则表达式判断整型
	 */
	public static boolean isNumeric(String str) {
		if (str == null || "".equals(str))
			return false;
		Pattern pattern = Pattern.compile("-?[0-9]*");
		return pattern.matcher(str).matches();
	}

	public static String M_TAG_STRING_BEGIN = "<M [0-9]+>";
	public static String M_TAG_STRING_END = "</M>";
	public static String AT_PATTERN_STRING = "@\\s*[a-zA-Z0-9\\u4e00-\\u9fa5]+\\s*(\\([0-9]{3,10}\\))?\\s*";

	public final static Pattern M_TAG_BEGIN_PATTERN = Pattern.compile(M_TAG_STRING_BEGIN);//用于从<M>里解析出
	public final static Pattern AT_M_TAG_PATTERN = Pattern
			.compile(new StringBuilder(M_TAG_STRING_BEGIN).append(AT_PATTERN_STRING)
					.append(M_TAG_STRING_END).toString());
	public final static Pattern AT_PATTERN = Pattern.compile(AT_PATTERN_STRING);// 匹配@
	public final static Pattern AT_UID_PATTERN = Pattern.compile("[0-9]+");
	
	
	public  final static Pattern HASHTAGS_PATTERN = Pattern
			.compile("#([^\\#|.]+)#");
	/**
	 * 修改Patterns.GOOD_IRI_CHAR，过滤双字节
	 */
	public static final String GOOD_IRI_CHAR ="a-zA-Z0-9";
	
	/**
	 * 修改系统的URL正则，过滤双字节，去除url后面必须带结束字节
	 * 
	 */
	public static final Pattern WEB_URL = Pattern.compile(
	        "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
	        + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
	        + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
	        + "((?:(?:[" + GOOD_IRI_CHAR + "][" + GOOD_IRI_CHAR + "\\-]{0,64}\\.)+"   // named host
	        + Patterns.TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL
	        + "|(?:(?:25[0-5]|2[0-4]" // or ip address
	        + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]"
	        + "|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]"
	        + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}"
	        + "|[1-9][0-9]|[0-9])))"
	        + "(?:\\:\\d{1,5})?)" // plus option port number
	        + "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~"  // plus option query params
	        + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?");
	       // + "(?:\\b|$)"); // and finally, a word boundary or end of
	                        // input.  This is to stop foo.sure from
	                        // matching as foo.su
	
}
